Page({

  /**
   * 页面的初始数据
   */
  data: {
    is_bind: false,
    is_contract: false,
    is_auth:false,
    list: [],
  },
  changeCard: function(e) {
    let {
      id
    } = e.currentTarget.dataset || {};
    wx.navigateTo({
      url: '/pages/changeCard/changeCard?id=' + id,
    })
  },
  toEvaluate: function() {
    wx.navigateTo({
      url: '/pages/evaluate/evaluate',
    })
  },
  newSigned: function() {
    wx.navigateTo({
      url: '/pages/newSigned/newSigned',
    })
  },
  // 选择服务商
  select_facilitator: function(e) {
    let {
      id
    } = e.currentTarget.dataset || {};
    wx.navigateTo({
      url: '/pages/selectFacilitator/selectFacilitator?id=' + id,
    })
  },
  // 去签约
  toSign: function(e) {
    let {
      id
    } = e.currentTarget.dataset || {};
    wx.navigateTo({
      url: '/pages/business/business?id=' + id + '&edit=' + 1,
    })
  },
  // 查看签约
  toSign1(e) {
    let {
      id
    } = e.currentTarget.dataset || {};
    wx.navigateTo({
      url: '/pages/business/business?id=' + id + '&edit=' + 2,
    })
  },
  // 签署报告
  sign_report(e){
    let {
      id
    } = e.currentTarget.dataset || {};
    wx.navigateTo({
      url: '/pages/signedReport/signedReport?id=' + id ,
    })  
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad:function(options) {
    console.log("二维码参数传入",options)
    console.log("二维码参数传入_scene", options.scene)
    
    this.init(options);
  },

  async  indexLoad(options){
    let that = this;
    let is_bind = wx.getStorageSync('is_bind');
    let is_contract = wx.getStorageSync('is_contract');
    let is_auth = wx.getStorageSync('is_auth');
    console.log('come indexlodad', is_bind, is_contract, is_auth);

    wx.showLoading({
      title: '加载中...',
      icon:"none"
    })
    that.setData({
      is_bind: is_bind,
      is_contract: is_contract,
      is_auth: is_auth
    })
    let to_page = (url) => {
      wx.reLaunch({
        url: url,
      })
    }
    if(!is_bind){
      //由于app.js 中调getopenid 的接口和进入 index 页面是一个异步过程，所以这里要做相应处理
      let go_url = '/pages/login/login';
      if (options.scene != undefined){    //如果带了参数过来
        go_url = go_url + '?scene=' + options.scene;
      }
      to_page(go_url);
    }else if(!is_auth){
      to_page('/pages/personalDetails/personalDetails');
    }else if(!is_contract){
      if (options.scene != undefined) {
        let go_url = '/pages/newSigned/newSigned?codes=' + options.scene;
        to_page(go_url);
      }else{
        to_page('/pages/newSigned/newSigned');
      }
    }else{
      if (options.scene != undefined){
        let go_url = '/pages/newSigned/newSigned?codes=' + options.scene;
        to_page(go_url);
      }else{
        let data = await wx.$api.myContractList({});
        that.setData({
          list: data.data.data || []
        })
      }
    }

  },

  async  wxLogin(){
    await  getApp().getOpenId();
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    console.log(1111111)
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    console.log(222222222222)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  async init(options){
    let that = this;
    await  that.wxLogin();
    await  that.indexLoad(options);
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})